﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace NetFluxCore
{
    public class OpenVPNConfig
    {
        string write;
        string config;
        public int Ping_Restart { get; set; }

        public OpenVPNConfig()
        {
            //Defaults
            Ping_Restart = 20;
        }

        public void Write()
        {
            write =
                @"client
dev tun
proto tcp
remote localhost 3130
nobind
persist-key
persist-tun
ping-restart $ping_restart$
no-replay
mute-replay-warnings
ca ca.crt
auth-user-pass username.txt
comp-lzo
verb 1
mute 20
connect-retry 2
pull
route 192.168.0.0 255.255.255.0 net_gateway
route 192.168.1.0 255.255.255.0 net_gateway
";   
        }

        public void ExcludeIP(IPAddress ip)
        {
            write += "\nroute <IP> 255.255.255.255 net_gateway".Replace("<IP>", ip.ToString());
        }

        public void Write(string path)
        {
            config = write;
            config = config.Replace("$ping_restart$", Ping_Restart.ToString());
            File.WriteAllText(path, config);
        }
    }
}
